package com.wyw.leetcode.learning.simple;

/**
 * leetcode topic 392
 * 判断子序列
 *
 * @Author Mr Wu    yewen.wu.china@gmail.com
 * <p>
 * Update History:
 * Author        Time            Content
 */
public class Topic392 {

    public static void main(String[] args) {

    }

    public static boolean isSubsequence(String s, String t) {
        int result = 0;

        final int lengthS = s.length();
        if(lengthS == 0) {
            return true;
        }
        final int lengthT = t.length();
        int i = 0;
        int j = 0;
        while (i<lengthS) {
            while (j<lengthT) {
                if(s.charAt(i) == t.charAt(j)) {
                    j++;
                    result++;
                    break;
                }
                j++;
            }
            i++;
        }
        return result == lengthS;
    }

    public static boolean isSubsequence1(String s, String t) {
        int index = -1;
        for (char c : s.toCharArray()){
            index = t.indexOf(c, index+1);
            if (index == -1) return false;
        }
        return true;
    }

    public static boolean isSubsequence2(String s, String t) {
        return false;
    }
}
